/*
 *  Copyright (c) 1993 Christopher J. Kane.  All rights reserved.
 *
 *  This software is subject to the terms of the MiscKit license
 *  agreement.  Refer to the license document included with the
 *  MiscKit distribution for these terms.
 *
 *  Version: 1.1 (22 October 1993)
 */

#import <misckit/MiscFindPanelClass.h>

@implementation Application (MiscFindPanelClass)

static BOOL _FPloaded=NO;
static BOOL _fpLoaded=NO;

- (Class)MiscFindPanelClass
{
  static Class _findPanelClass=Nil;
  if (!_FPloaded)
    {
      char path[MAXPATHLEN+16];
      _FPloaded = YES;
      sprintf(path, "%s/MiscFindPanel.bundle", [[NXBundle mainBundle] directory]);
      _findPanelClass = [[[NXBundle alloc] initForDirectory:path] classNamed:"MiscFindPanel"];
      if ([[NXApp delegate] respondsTo:@selector(MiscFindPanelClassWasLoaded:)])
        _findPanelClass = [[NXApp delegate] MiscFindPanelClassWasLoaded:_findPanelClass];
      else if ([NXApp respondsTo:@selector(MiscFindPanelClassWasLoaded:)])
        _findPanelClass = [NXApp MiscFindPanelClassWasLoaded:_findPanelClass];
    }
  return _findPanelClass;
}

- (BOOL)isMiscFindPanelClassLoaded
{
  return _FPloaded;
}

- (MiscFindPanel *)findPanel
{
  static MiscFindPanel *_findPanel=nil;
  if (!_fpLoaded)
    {
      if ([[NXApp delegate] respondsTo:@selector(findPanelWillLoad:)])
        [[NXApp delegate] findPanelWillLoad:[self MiscFindPanelClass]];
      else if ([NXApp respondsTo:@selector(findPanelWillLoad:)])
        [NXApp findPanelWillLoad:[self MiscFindPanelClass]];
      _findPanel = [[self MiscFindPanelClass] sharedInstance];
      if ([[NXApp delegate] respondsTo:@selector(findPanelDidLoad:)])
        _findPanel = [[NXApp delegate] findPanelDidLoad:_findPanel];
      else if ([NXApp respondsTo:@selector(findPanelDidLoad:)])
        _findPanel = [NXApp findPanelDidLoad:_findPanel];
      _fpLoaded = YES;
    }
  return _findPanel;
}

- (BOOL)isFindPanelLoaded
{
  return _fpLoaded;
}

- enterSelection:sender
{
  return [[self findPanel] enterSelection:sender];
}

- findNext:sender
{
  return [[self findPanel] findForward:sender];
}

- findPrevious:sender
{
  return [[self findPanel] findBackward:sender];
}

- jumpToSelection:sender
{
  return [[self findPanel] jumpToSelection:sender];
}

- orderFrontFindPanel:sender
{
  return [[self findPanel] makeKeyAndOrderFront:sender];
}

- orderFrontRangePanel:sender
{
  return [[self findPanel]  orderFrontRangePanel:sender];
}

@end
